package com.zipou.framework.persistence;

import java.lang.reflect.Proxy;
import java.util.logging.Logger;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;


public class MyEntityManagerFactory {

	private static final Logger log = Logger.getLogger(MyEntityManagerFactory.class.getName());
	/**
	 * 
	 *  Rendre dynamique dans un properties le choix de l'EntityManager
	 *  
	 */
	private static final EntityManagerFactory pmfInstance = Persistence.createEntityManagerFactory("transactions-optional");
	
	public static EntityManager createEntityManager() { 
		if(pmfInstance == null) { 
			log.severe("EntityManagerFactory nulle !");
		}
		//		return (EntityManager) Proxy.newProxyInstance(EntityManager.class.getClassLoader(), new Class[] {EntityManager.class}, new MyInvocationHandler(PMF.get().createEntityManager()));
		return (EntityManager) Proxy.newProxyInstance(EntityManager.class.getClassLoader(), new Class[] {EntityManager.class}, new MyInvocationHandler(pmfInstance.createEntityManager()));
	}

} 

